import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

import 'package:get/get.dart';
import 'package:oktoast/oktoast.dart';
import 'package:practice/practice.dart';
import 'package:practice_example/routers/get_routers.dart';
import 'package:practice_example/utli/colors.dart';

void main() {
  runApp(MyApp());
  SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle(
      statusBarColor: Colors.transparent,
      statusBarIconBrightness: Brightness.light));
}

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  String _platformVersion = 'Unknown';

  @override
  void initState() {
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return ScreenUtilInit(
        designSize: Size(375, 812),
        builder: () => OKToast(
              textStyle: TextStyle(fontSize: 13.0, color: Colors.white),
              backgroundColor: Colors.grey[850],
              radius: 25.0,
              textPadding:
                  EdgeInsets.only(left: 20, right: 20, top: 10, bottom: 10),
              position: ToastPosition.bottom,
              child: GetMaterialApp(
                defaultTransition: Transition.fade,
                getPages: GetRouters.getRouters(),
                unknownRoute: GetRouters.getUnknowRouter(),
                theme: ThemeData(
                    brightness: Brightness.light,
                    scaffoldBackgroundColor: Colors.white,
                    primarySwatch: white),
                builder: (context, child) {
                  return GestureDetector(
                    onTap: () {
                      FocusManager.instance.primaryFocus?.unfocus();
                    },
                    child: child,
                  );
                },
                home: Scaffold(
                  appBar: AppBar(
                    title: const Text('Plugin example app'),
                  ),
                  body: Center(
                    child: Column(
                      mainAxisAlignment: MainAxisAlignment.center,
                      children: [
                        ElevatedButton(
                          child: Text("学校管理员"),
                          onPressed: organAdmin,
                        ),
                        ElevatedButton(
                          child: Text("教师"),
                          onPressed: teacher,
                        ),
                        ElevatedButton(
                          child: Text("在校生"),
                          onPressed: inStudent,
                        ),
                        ElevatedButton(
                          child: Text("离校生"),
                          onPressed: outStudent,
                        ),
                        ElevatedButton(
                          child: Text("企业人员"),
                          onPressed: company,
                        ),
                      ],
                    ),
                  ),
                ),
              ),
            ));
  }

  ///学校管理员
  void organAdmin() async {
    Map<String, dynamic> user = {
      "id": "1",
      "userId": "f45db1ec2c26476f8bcbb0e106078d70",
      "realName": "李博雅",
      "userName": "liboya",
      "phone": "15210582453",
      "avatar":
          "https://studycloud-test.oss-cn-hangzhou.aliyuncs.com/44c786d0-c922-11eb-a79c-274be8940773.jpg",
      "clientId": "6D3E260A8319451F4575F64EFB3BA267",
    };
    Map<String, dynamic> organ = {
      "institutionId": "1",
      "institutionName": "测试大学-辽宁省沈阳市幼乐美机构",
      "privateKey": "59efe84f9878482f9e826180ae1a8e2c",
      "courseAuth": 1,
    };

    await Practice.config(
        user: user,
        organ: organ,
        roleType: 1,
        isDebug: true,
        onResult: (action) {});
    Get.toNamed(PracticeRouters.practiceOrgan);
  }

  ///教师
  void teacher() async {
    Map<String, dynamic> user = {
      "id": "1",
      "userId": "f45db1ec2c26476f8bcbb0e106078d70",
      "realName": "李博雅",
      "userName": "liboya",
      "phone": "15210582453",
      "avatar":
          "https://studycloud-test.oss-cn-hangzhou.aliyuncs.com/44c786d0-c922-11eb-a79c-274be8940773.jpg",
      "clientId": "6D3E260A8319451F4575F64EFB3BA267",
    };
    Map<String, dynamic> organ = {
      "institutionId": "1",
      "institutionName": "测试大学-辽宁省沈阳市幼乐美机构",
      "privateKey": "59efe84f9878482f9e826180ae1a8e2c",
      "courseAuth": 1,
    };

    await Practice.config(
        user: user,
        organ: organ,
        roleType: 2,
        isDebug: true,
        onResult: (action) {});
    Get.toNamed(PracticeRouters.practiceTeacher);
  }

  ///在校生
  void inStudent() async {
    Map<String, dynamic> user = {
      "id": "345577961640873984",
      "userId": "345577961640873984",
      "realName": "李博雅",
      "userName": "liboya",
      "phone": "15210582453",
      "avatar":
          "https://studycloud-test.oss-cn-hangzhou.aliyuncs.com/44c786d0-c922-11eb-a79c-274be8940773.jpg",
      "clientId": "6D3E260A8319451F4575F64EFB3BA267",
    };
    Map<String, dynamic> organ = {
      "institutionId": "1",
      "institutionName": "测试大学-辽宁省沈阳市幼乐美机构",
      "privateKey": "59efe84f9878482f9e826180ae1a8e2c",
      "courseAuth": 1,
    };

    await Practice.config(
        user: user,
        organ: organ,
        roleType: 3,
        isDebug: true,
        onResult: (action) {});
    Get.toNamed(PracticeRouters.practiceStudentIn);
  }

  ///离校生
  void outStudent() async {
    Map<String, dynamic> user = {
      "id": "361888213119512576",
      "userId": "361888213119512576",
      "realName": "李博雅",
      "userName": "liboya",
      "phone": "15210582453",
      "avatar":
          "https://studycloud-test.oss-cn-hangzhou.aliyuncs.com/44c786d0-c922-11eb-a79c-274be8940773.jpg",
      "clientId": "6D3E260A8319451F4575F64EFB3BA267",
    };
    Map<String, dynamic> organ = {
      "institutionId": "345577961640873984",
      "institutionName": "测试大学-辽宁省沈阳市幼乐美机构",
      "privateKey": "59efe84f9878482f9e826180ae1a8e2c",
      "courseAuth": 1,
    };
    await Practice.config(
        user: user,
        organ: organ,
        roleType: 4,
        isDebug: true,
        onResult: (action) {});
    Get.toNamed(PracticeRouters.practiceStudentOut);
  }

  void company() async {
    Map<String, dynamic> user = {
      "id": "1",
      "userId": "f45db1ec2c26476f8bcbb0e106078d70",
      "realName": "李博雅",
      "userName": "liboya",
      "phone": "15210582453",

      ///企业id
      "companyId": "1",
      "avatar":
          "https://studycloud-test.oss-cn-hangzhou.aliyuncs.com/44c786d0-c922-11eb-a79c-274be8940773.jpg",
      "clientId": "6D3E260A8319451F4575F64EFB3BA267",
    };
    Map<String, dynamic> organ = {
      "institutionId": "1",
      "institutionName": "测试大学-辽宁省沈阳市幼乐美机构",
      "privateKey": "59efe84f9878482f9e826180ae1a8e2c",
      "courseAuth": 1,
    };
    await Practice.config(
        user: user,
        organ: organ,
        roleType: 5,
        isDebug: true,
        onResult: (action) {});
    Get.toNamed(PracticeRouters.practiceCompany);
  }
}
